package com.atguigu.day21.bytestream;

import org.junit.Test;

import java.io.*;

/*
IO: input output 输入和输出
分类:
    流向分:
         输入和输出
    数据分:
        字节和字符
    角色分:
        节点和处理
四大基流 (抽象类):
   字节流
       InputStream
       OutputStream
   字符流:
       Reader
       Writer

字节输出流:
    以字节为单位写出数据
       字节输出流对象.write(数字)
       字节输出流对象.write(字节数组)

 */
public class OutputStreamTest {

    @Test
    public void test04() throws IOException {
        OutputStream os = new FileOutputStream("D:/aaa.txt");

        os.write(65);
        byte[] bytes = {66,67,68,69};
        os.write(bytes);

        String s = "\njava我终于学会了";
        byte[] bytes1 = s.getBytes();
        os.write(bytes1);

        os.close();
    }


    @Test
    public void test03() throws IOException {
     OutputStream os = new FileOutputStream("C:/abc/a.txt");

     os.write(65);

     os.close();
    }

    @Test
    public void test02() throws IOException {
     //1.创建对象
        OutputStream os = new FileOutputStream("D:/os.txt");
        //2.写出数据

        String s = "我爱java 我不困";
        byte[] bytes = s.getBytes();
        os.write(bytes);

        String s2 = "\n哈哈  你好";

        byte[] bytes1 = s2.getBytes();

        os.write(bytes1);


        //3.关闭资源
        os.close();

    }

    @Test
    public void test01() throws IOException {
        //1.创建字节输出流对象
        OutputStream os = new FileOutputStream("D:/os.txt",true);
        //2.写出数据
        os.write(65);
        os.write(66);
         byte[]bArr = {65,66,67,68,69};
         os.write(bArr);
        //3.关闭资源
        os.close();

        System.out.println("写出完毕");


    }
}
